package com.pc.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pc.entity.Food;
import com.pc.mapper.FoodMapper;
import com.pc.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FoodService {
    @Resource
    private FoodMapper foodMapper;

    //根据查询结果显示菜品
    public Result getCategoryFood(String category){
        QueryWrapper<Food> wrapper = new QueryWrapper<>();
        wrapper.eq("category", category);
        List<Food> foods = foodMapper.selectList(wrapper);
        if(foods.size()>0)
            return Result.success("查询菜品成功",foods);
        else
            return Result.fail("获取菜品失败");
    }
    //搜索功能
    public String getCategory(String foodname){
        QueryWrapper<Food> wrapper = new QueryWrapper<>();
        wrapper.eq("name",foodname);
        Food food = foodMapper.selectOne(wrapper);
        if(food==null)
            return "没有查询到";
        else
            return food.getCategory();
    }

    //显示全部菜品
    public List<Food> getAllFood(){
        QueryWrapper<Food> wrapper = new QueryWrapper<>();
        return foodMapper.selectList(wrapper);
    }

    //更改菜品价格
    public boolean modifyFoodPrice(int id,int price){
        QueryWrapper<Food> wrapper = new QueryWrapper<>();
        wrapper.eq("id",id);
        Food food = new Food();
        food.setPrice(price);
        int update = foodMapper.update(food, wrapper);
        return update!=0;
    }
    //查询某个商品Pc端
    public List<Food> getFoodByname(String foodname){
        QueryWrapper<Food> wrapper = new QueryWrapper<>();
        wrapper.eq("name",foodname);
        return foodMapper.selectList(wrapper);
    }
}


